import {defineConfig,loadEnv} from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import AutoImport from 'unplugin-auto-import/vite'
// @ts-ignore
import TransformPages from "./routerPlugins.js"; // 路由插件
const tfPages = new TransformPages({ // 路由插件配置
    includes: ['path', 'name', 'aliasPath', 'meta']
})

// https://vitejs.dev/config/
// https://cn.vitejs.dev/config/server-options.html#server-host
export default defineConfig(({ command, mode }) => {
    // @ts-ignore
    const env = loadEnv(mode, process.cwd(), 'VITE_') // 加载环境变量
    // console.log('env', env)
    return{
        build: {
            sourcemap: mode === 'development', // 开发环境下生成sourcemap
        },
        define: {
            ROUTER: JSON.stringify(tfPages.routes),
        },
        plugins: [
            uni(),
            AutoImport({
                imports: [
                    'vue',
                ],
            }),
        ],
        server: { // 配置本地服务
            port: 9527,
        }
    }
});
